#include "Wave.h"
#include "SDL.h"
#include "EnemyBase.h"


Wave::Wave(void):Manager()
{
	spawnRate = 10;
	activeEnemies = 0;
	timer = 0;
}


Wave::~Wave(void)
{

}

void Wave::getFirst(std::vector<EnemyBase*>::iterator & _it)
{
	_it = elements.begin();
}

void Wave::getLast(std::vector<EnemyBase*>::iterator & _it)
{
	_it = elements.end();
}

void Wave::drawAllEnemies(SDL_Renderer * renderer)
{
	for(int i = 0;i < activeEnemies;i++)
	{
		elements[i]->draw(renderer);
	}
}
void Wave::updateAllEnemies()
{
	for(int i = 0;i<activeEnemies;i++)
	{
		if(elements[i] != NULL)
		{
			if(elements[i]->alive())
				elements[i]->update();
			else 
			{
				activeEnemies--;
				deleteElement(elements[i]);		
			}
		}
	}
}

void Wave::setSpawnRate(int rate)
{
	spawnRate = rate;
}

int Wave::getSpawnRate()
{
	return spawnRate;
}

void Wave::updateWave()
{
	if(activeEnemies < elements.size())
	{
		timer ++;
		if(timer == spawnRate)
		{
			activeEnemies++;
			timer = 0;
		}
	}
}

int Wave::getNumberOfActiveEnemies()
{
	return activeEnemies;
}